﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Globalization;
using System.IO;

public partial class admin_updateUser : System.Web.UI.Page
{
    db_users user = new db_users();
    public string picUrl = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        Server.Execute("../inc/checkPurview.aspx");  // 此处用户权限验证

        if (Request.QueryString["id"] == null)
        {
            Response.Redirect("manageUser.aspx");
        }
        
        if (!IsPostBack)
        {
            this.bind_user();
        }
    }
    protected void btn_ok_Click(object sender, EventArgs e)
    {
        string id = tb_id.Text;
        string name = tb_name.Text;
        string email = tb_email.Text;
        string sex;
        if (rbtn_man.Checked)
        {
            sex = "男";
        }
        else {
            sex = "女";
        }
        string status = ddl_status.SelectedValue;
        if (user.updateUser(id,name,email,sex,status))
        {
            Response.Write("<script language=javascript>alert('修改成功！');</script>");
        }
        else
        {
            Response.Write("<script language=javascript>alert('失败！')</script>");
        }
    }
    protected void btn_res_Click(object sender, EventArgs e)
    {
        this.bind_user();   
    }

    private void bind_user()
    {
        string userID = Request.QueryString["id"].ToString();
        DataSet ds = user.selectUserONE_id(userID);
        tb_id.Text = ds.Tables[0].Rows[0]["userID"].ToString();
        tb_name.Text = ds.Tables[0].Rows[0]["userName"].ToString();
        tb_email.Text = ds.Tables[0].Rows[0]["email"].ToString();
        if ("男".Equals(ds.Tables[0].Rows[0]["sex"].ToString()))
        {
            rbtn_man.Checked = true;
        }
        else
        {
            rbtn_woman.Checked = true
;
        }
        ddl_status.SelectedValue = ds.Tables[0].Rows[0]["status"].ToString();
    }
}